package com.clinic.entity.db;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = Prescription.TABLE)
public class Prescription implements Serializable{

	private static final long serialVersionUID = -3217720137329271882L;
	
	public static final String TABLE = "prescription";
	
	public class Columns{
		public static final String PRESCRIPTION_ID = "prescriptionId";
		public static final String ROOT_PRESCRIPTION_ID = "rootPrescriptionId";
		public static final String DIAGNOSTIC_DESCRIPTION = "diagnosticDescription";
		public static final String COMMENT = "comment";
		public static final String DATE = "date";
		public static final String VISIT_INDEX = "visitIndex";
		public static final String USER_ID = "userId";
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = Columns.PRESCRIPTION_ID)
	private long prescriptionId;
	
	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = Columns.ROOT_PRESCRIPTION_ID)
    private Prescription rootPrescription;
 
    @OneToMany(mappedBy = "rootPrescription", cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Prescription> subPrescriptions;
	
	@Column(name = Columns.DIAGNOSTIC_DESCRIPTION)
	private String diagnosticDescription;
	
	@Column(name = Columns.COMMENT)
	private String comment;
	
	@Column(name = Columns.DATE)
	private Date date;
	
	@Column(name = Columns.VISIT_INDEX)
	private int visitIndex;
	
	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = Columns.USER_ID)
	private Patient patient;
	
	@OneToMany(mappedBy="prescription", cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<DrugIssue> issues;
	
	@ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name="prescriptionsyptom",
	    joinColumns={@JoinColumn(name="prescriptionId")},
	    inverseJoinColumns={@JoinColumn(name="syptomId")})
    private Set<Syptom> syptoms;

	public long getPrescriptionId() {
		return prescriptionId;
	}

	public void setPrescriptionId(long prescriptionId) {
		this.prescriptionId = prescriptionId;
	}

	public Prescription getRootPrescription() {
		return rootPrescription;
	}

	public void setRootPrescription(Prescription rootPrescription) {
		this.rootPrescription = rootPrescription;
	}

	public List<Prescription> getSubPrescriptions() {
		return subPrescriptions;
	}

	public void setSubPrescriptions(List<Prescription> subPrescriptions) {
		this.subPrescriptions = subPrescriptions;
	}

	public String getDiagnosticDescription() {
		return diagnosticDescription;
	}

	public void setDiagnosticDescription(String diagnosticDescription) {
		this.diagnosticDescription = diagnosticDescription;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getVisitIndex() {
		return visitIndex;
	}

	public void setVisitIndex(int visitIndex) {
		this.visitIndex = visitIndex;
	}

	public Patient getPatient() {
		return patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}

	public Set<DrugIssue> getIssues() {
		return issues;
	}

	public void setIssues(Set<DrugIssue> issues) {
		this.issues = issues;
	}

	public Set<Syptom> getSyptoms() {
		return syptoms;
	}

	public void setSyptoms(Set<Syptom> syptoms) {
		this.syptoms = syptoms;
	}
	
}
